﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeChat.JsSDK.lib;
using WeChat.Common2;

namespace WeChat.JsSDK.WxPayTest
{
    public partial class WxPay : System.Web.UI.Page
    {
        public static string wxJsApiParam { get; set; } //H5调起JS API参数
        public string total_feeShow;   //页面展示商品价格
        public string goodsName;       //页面展示商品名
        public string CompanyName;     //页面展示公司名称
        public static string domainName = Config.domainName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string openid = Request.QueryString["openid"];
                string total_fee = Request.QueryString["total_fee"];
                string pay = Request.QueryString["pay"];
                //检测是否给当前页面传递了相关参数
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                    return;
                }

                total_feeShow = (Double.Parse(total_fee) / 100).ToString();
                if (pay == "addmoney")
                {
                    goodsName = Config.body;
                    CompanyName = Config.CompanyName;
                }
                else
                {
                    goodsName = "订餐消费";
                    CompanyName = Config.CompanyName;
                }
                //JSAPI支付预处理
                try
                {
                    wxJsApiParam = WxPayApi.getPayJson(openid, total_fee, pay,"","");//获取H5调起JS API参数      
                }
#pragma warning disable CS0168 // 声明了变量“ex”，但从未使用过
                catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”，但从未使用过
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败，请返回重试" + openid + total_fee + "</span>");
                }
            }
        }
    }
}


